home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / ddepm / ddepm.bas next >
Encoding:
BASIC Source File  |  1995-05-09  |  27.5 KB  |  755 lines

  1. '------------------------------------------------------------------------
  2. '-- DDEPM.BAS - Copyright (c) 1993 Gregg S. Irwin
  3. '
  4. '-- You may use, modify, reproduce and distribute this module (and/or
  5. '   any modified version) in any way you find useful. It is provided as
  6. '   is and no warranties of any kind whatsoever are provided. It is not
  7. '   a completed product, just a starting point to get you going.
  8. '
  9. '-- If you make any modicfications or post updated versions please leave
  10. '   this message in place and add your own name and comments as well as
  11. '   what changes were made. If you do update it please send me a note or
  12. '   a copy about what you're doing with it, that helps make the effort
  13. '   worthwhile.<g> If you have questions or comments you can reach me at
  14. '   CIS:ID[72450,676]. Enjoy!
  15. '
  16. '--   Date        Version       Author                  Notes
  17. '------------------------------------------------------------------------
  18. '   09/09/93       1.00         Gregg S. Irwin   Thanks to Thomas R. Goulding for his feedback
  19. '                                                and Hot-Key detecitve work.
  20. '
  21. '------------------------------------------------------------------------
  22. Option Explicit
  23. DefInt A-Z
  24.  
  25.  
  26. Type T_ProgManGroupItem
  27.     Name            As String
  28.     CmdLine         As String
  29.     IconPath        As String
  30.     IconIndex       As Integer
  31.     xPos            As Integer
  32.     yPos            As Integer
  33.     DefaultDir      As String
  34.     HotKey          As Integer
  35.     RunMinimized    As Integer
  36. End Type
  37.  
  38.  
  39. Global Const HOTKEY_MOD_SHIFT = &H100
  40. Global Const HOTKEY_MOD_CTRL = &H200
  41. Global Const HOTKEY_MOD_ALT = &H400
  42.  
  43. ' Used by ParseString
  44. Global Const ERR_ITEMS_TRUNCATED = -2
  45.  
  46. '---------------------------------------------------
  47. '-- Comment out the lines below if you have them
  48. '   declared in another module in your application.
  49. '---------------------------------------------------
  50. Global Const NONE = 0
  51.  
  52. ' Message Box
  53. Global Const MB_OK = 0
  54.  
  55. ' MousePointer
  56. Global Const DEFAULT = 0        ' 0 - Default
  57. Global Const HOURGLASS = 11     ' 11 - Hourglass
  58.  
  59. ' LinkMode (forms and controls)
  60. Global Const LINK_NONE = 0      ' 0 - None
  61. Global Const LINK_SOURCE = 1    ' 1 - Source (forms only)
  62. Global Const LINK_AUTOMATIC = 1 ' 1 - Automatic (controls only)
  63. Global Const LINK_MANUAL = 2    ' 2 - Manual (controls only)
  64. Global Const LINK_NOTIFY = 3    ' 3 - Notify (controls only)
  65.  
  66. Sub ddepmAddItem (lblLink As Label, CmdLine$, ItemName$)
  67. '-----------------------------------------------------------
  68. '-- This is the basic version. ddepmAddItemExt gives you
  69. '   more options but you may never use them so why make it
  70. '   any harder than it should be? Oh Yeah, its purpose is
  71. '   to add an icon to an existing ProgMan group.
  72. '
  73. '-- Arguments: lblLink     The Label used for DDE with
  74. '                          Progman.
  75. '              CmdLine$    A string that contains the
  76. '                          command line for the item/icon.
  77. '                          i.e. "c:\myapp\setup.exe"
  78. '              ItemName$   A string that contains the item's
  79. '                          caption.
  80. '-----------------------------------------------------------
  81.     Dim ddeCmd$
  82.     
  83.     ddeCmd$ = "[AddItem(" & CmdLine$ + "," & ItemName$ & ")]"
  84.     Call ddepmExecute(lblLink, ddeCmd$)
  85.  
  86.  
  87. End Sub
  88.  
  89. Sub ddepmAddItemExt (lblLink As Label, CmdLine$, ItemName$, IconPath$, IconIndex%, xPos%, yPos%, DefaultDir$, HotKey%, RunMinimized%)
  90. '------------------------------------------------------------
  91. '-- This is the extended version of ddepmAddItem. This
  92. '   version allows you to use all the parameters supported
  93. '   by the AddItem command.
  94. '
  95. '-- Arguments: lblLink     The Label used for DDE with
  96. '                          Progman.
  97. '              CmdLine$    A string that contains the
  98. '                          command line for the item/icon.
  99. '                          i.e. "c:\myapp\setup.exe"
  100. '              ItemName$   A string that contains the item's
  101. '                          caption.
  102. '              IconPath$   Identifies the Filename for the
  103. '                          Icon to be displayed in the
  104. '                          group window.
  105. '              IconIndex%  Specifies the Index of the Icon
  106. '                          in the file identified by the
  107. '                          IconPath$ parameter.
  108. '              xPos%       Specifies the horizontal position
  109. '                          of the Icon in the group window
  110. '              yPos%       Specifies the vertical position
  111. '                          of the Icon in the group window
  112. '              DefaultDir$ Specifies the working directory
  113. '              HotKey%     Identifies a hot-key that is
  114. '                          specified by the user. Note that
  115. '                          this is an Integer. It's the Ascii
  116. '                          value of the HotKey.
  117. '            RunMinimized% Specifies whether an application
  118. '                          window should be minimized when
  119. '                          it is first displayed.
  120. '------------------------------------------------------------
  121.     Dim ddeCmd$
  122.     
  123.     ddeCmd$ = "[AddItem(" & CmdLine$ & "," & ItemName$ & ","
  124.     ddeCmd$ = ddeCmd$ & IconPath$ & "," & IconIndex% & ","
  125.     ddeCmd$ = ddeCmd$ & xPos% & "," & yPos% & ","
  126.     ddeCmd$ = ddeCmd$ & DefaultDir$ & "," & HotKey% & ","
  127.     ddeCmd$ = ddeCmd$ & RunMinimized% & ")]"
  128.     
  129.     Call ddepmExecute(lblLink, ddeCmd$)
  130.  
  131. End Sub
  132.  
  133. Sub ddepmAddItemExtT (lblLink As Label, tItem As T_ProgManGroupItem)
  134. '-----------------------------------------------------------
  135. '-- This is the Type'd version of ddepmAddItemExt. The Type
  136. '   definition in the declarations section covers all the
  137. '   parameters you need for a ProgMan Item. This is just an
  138. '   idea that may help if you have a bunch of items, maybe
  139. '   in a setup INI file, and you want to grab them into an
  140. '   array of Type variables so you can just loop through
  141. '   that array to add all the items. If you think it's
  142. '   useless go ahead and yank it(and the associated
  143. '   pmItemCmdLineFromTypeVar procedure). Oh yeah, if you're
  144. '   creating a bunch of items then it will also be a whole
  145. '   lot more efficient to pass a Type Variable as opposed to
  146. '   all those parameters.
  147. '
  148. '-- Arguments: lblLink     The Label used for DDE with
  149. '                          Progman.
  150. '              tItem       A Type Variable that should be
  151. '                          initialized with all the data
  152. '                          required for advanced setup.
  153. '
  154. '-- See ddepmAddItemExt for an explanation of what each
  155. '   element in the type specifies.
  156. '-----------------------------------------------------------
  157.     Dim ddeCmd$
  158.     Dim ItemCmdLine$
  159.     
  160.     '-- Build a commmand Line based on the elements of Item
  161.     ItemCmdLine$ = pmItemCmdLineFromTypeVar(tItem)
  162.     
  163.     ddeCmd$ = "[AddItem(" & ItemCmdLine$ & ")]"
  164.     Call ddepmExecute(lblLink, ddeCmd$)
  165.  
  166.  
  167. End Sub
  168.  
  169. Sub ddepmCreateGroup (lblLink As Label, GroupName$, GroupPath$)
  170. '----------------------------------------------------------------
  171. '-- Creates a new ProgMan group. If a group already exists with
  172. '   the name GroupName$ then that group will be activated
  173. '   rather than creating a new group.
  174. '
  175. '-- Arguments: lblLink     The Label used for DDE with Progman.
  176. '              GroupName$  A string that contains the group name
  177. '              GroupPath$  A string that contains the group file
  178. '                          name.(i.e. "myapp.grp") It must
  179. '                          be a valid DOS file name.
  180. '----------------------------------------------------------------
  181.     Dim ddeCmd$
  182.     
  183.     ddeCmd$ = "[CreateGroup(" & GroupName$ + "," & GroupPath$ & ")]"
  184.     Call ddepmExecute(lblLink, ddeCmd$)
  185.  
  186. End Sub
  187.  
  188. Sub ddepmDeleteGroup (lblLink As Label, GroupName$)
  189. '-----------------------------------------------------------
  190. '-- This procedure deletes an existing ProgMan group.
  191. '
  192. '-- Arguments: lblLink     The Label used for DDE with
  193. '                          Progman.
  194. '              GroupName$  Name of the Group to Delete.
  195. '-----------------------------------------------------------
  196.     Dim ddeCmd$
  197.     
  198.     ddeCmd$ = "[DeleteGroup(" & GroupName$ & ")]"
  199.     Call ddepmExecute(lblLink, ddeCmd$)
  200.               
  201.  
  202. End Sub
  203.  
  204. Sub ddepmDeleteItem (lblLink As Label, ItemName$, GroupName$)
  205. '-----------------------------------------------------------
  206. '-- Deletes the ItemName$ icon from the group GroupName$.
  207. '   If GroupName$ is Null("") then ItemName$ will be deleted
  208. '   from the currently active group.
  209. '
  210. '-- Arguments: lblLink     The Label used for DDE with
  211. '                          Progman.
  212. '              ItemName$   A string that contains the
  213. '                          name of the item/icon to delete.
  214. '-----------------------------------------------------------
  215.     Dim ddeCmd$
  216.     
  217.     If Len(GroupName$) Then
  218.         Call ddepmShowGroup(lblLink, GroupName$, 1)
  219.     End If
  220.  
  221.     ddeCmd$ = "[DeleteItem(" & ItemName$ & ")]"
  222.     Call ddepmExecute(lblLink, ddeCmd$)
  223.  
  224.  
  225. End Sub
  226.  
  227. Private Sub ddepmErrorHandler (theError%)
  228. '------------------------------------------------------------
  229. '-- Pretty extravagant huh?<g> You can decide how you
  230. '   want to handle the DDE errors in your own app. I may
  231. '   post an update in the future if I come up with something
  232. '   really good.
  233. '------------------------------------------------------------
  234.     Dim Msg$
  235.     Dim Cap$
  236.     
  237.     Msg$ = Error$(theError%)
  238.     Cap$ = "ProgMan DDE Error"
  239.  
  240.     MsgBox Msg$, MB_OK, Cap$
  241.  
  242.  
  243. End Sub
  244.  
  245. Private Sub ddepmExecute (CtlLink As Control, ddeCmd$)
  246. '--------------------------------------------------------
  247. '-- Execute the DDECommand String through a LinkExecute
  248. '   for the CtlLink control.
  249. '
  250. '-- NOTE: Only Text Boxes, Picture Boxes, and Labels are
  251. '         valid controls to use.
  252. '--------------------------------------------------------
  253.     Dim i%
  254.     Dim OldLinkTimeout%
  255.  
  256.     Screen.MousePointer = HOURGLASS
  257.     
  258.     '-- Save the LinkTimeout so we can leave
  259.     '   it like we found it.
  260.     OldLinkTimeout% = CtlLink.LinkTimeout
  261.  
  262.     On Error GoTo ddepmExecuteError
  263.         '---------------------------------------------------------
  264.         '-- Set LinkTopic to PROGRAM MANAGER
  265.         '---------------------------------------------------------
  266.         CtlLink.LinkTopic = "ProgMan|Progman"
  267.         CtlLink.LinkMode = LINK_MANUAL
  268.         
  269.         For i% = 1 To 10
  270.             DoEvents
  271.         Next i%
  272.         
  273.         CtlLink.LinkTimeout = 100
  274.         
  275.         '---------------------------------------------------------
  276.         '-- Execute the DDE Command. The burden of making sure the
  277.         '   DDECommand is valid rests on the calling program or
  278.         '   routine. Normally I wouldn't want to do it that way
  279.         '   but this is a Private Procedure so only the other
  280.         '   procs in this module can get at it so it's my own
  281.         '   fault if something goes wrong.
  282.         '---------------------------------------------------------
  283.         CtlLink.LinkExecute ddeCmd$
  284.     
  285.     On Error GoTo 0
  286.     
  287.     '---------------------------------------------------------
  288.     '-- Reset properties
  289.     '---------------------------------------------------------
  290.     CtlLink.LinkTimeout = OldLinkTimeout%
  291.     CtlLink.LinkMode = NONE
  292.     
  293.  
  294. ddepmExecuteExit:
  295.     Screen.MousePointer = DEFAULT
  296.     On Error GoTo 0
  297.     Exit Sub
  298.  
  299. ddepmExecuteError:
  300.     Call ddepmErrorHandler(Err)
  301.     Resume ddepmExecuteExit
  302.  
  303.  
  304. End Sub
  305.  
  306. Sub ddepmExitProgMan (lblLink As Label, bSaveGroups%)
  307. '-----------------------------------------------------------
  308. '-- This only works if ProgMan is not the Shell
  309. '
  310. '-- Arguments: lblLink       The Label used for DDE with
  311. '                            Progman.
  312. '              bSaveGroups%  An integer telling Progman to
  313. '                            save Group information before
  314. '                            closing if it's non-zero.
  315. '-----------------------------------------------------------
  316.     Dim ddeCmd$
  317.     
  318.     ddeCmd$ = "[ExitProgman(" & bSaveGroups% & ")]"
  319.     Call ddepmExecute(lblLink, ddeCmd$)
  320.  
  321.  
  322. End Sub
  323.  
  324. Function ddepmGetGroups% (lblLink As Label, arrGroups$())
  325. '---------------------------------------------------------
  326. '-- Returns: True if all goes well.
  327. '            False if any DDE errors occur. If this is the
  328. '             case then no group names will have been
  329. '             loaded.
  330. '            ERR_ITEMS_TRUNCATED(-2) if an error occurs
  331. '             while parsing the Group Names.
  332. '
  333. '-- NOTE:    Even if errors occur(-2) some GroupNames may
  334. '            have been loaded successfully into the array.
  335. '
  336. '-- Returns arrGroups$() filled with all the available
  337. '   groups in ProgMan. The array is 0 based so the calling
  338. '   procedure should read from 0 to Ubound(arrGroups$) -1
  339. '   in order to read all the group names.
  340. '
  341. '-- arrGroups$() should be a dynamic string array. This
  342. '   procedure will resize it as necessary.
  343. '---------------------------------------------------------
  344.     Dim i%
  345.     Dim OldLinkTimeout%
  346.     Dim GroupList$
  347.     Dim Delimiter$
  348.     Dim NumGroups%
  349.     Dim CRLFPos%
  350.     Dim GroupsParsedOK%
  351.  
  352.     OldLinkTimeout% = lblLink.LinkTimeout
  353.  
  354.     '---------------------------------------------------------
  355.     '-- Set LinkTopic to PROGRAM MANAGER
  356.     '---------------------------------------------------------
  357.     lblLink.LinkTopic = "ProgMan|Progman"
  358.     lblLink.LinkMode = LINK_MANUAL
  359.     lblLink.LinkTimeout = 100
  360.     
  361.     On Error GoTo ddepmGetGroupsError
  362.         '---------------------------------------------------------
  363.         '-- Ask for the program manager group information
  364.         '   (returned in lblLink.Caption)
  365.         '---------------------------------------------------------
  366.         lblLink.LinkItem = "PROGMAN"
  367.         lblLink.LinkRequest
  368.         
  369.         '-- Set return value
  370.         GroupList$ = lblLink.Caption
  371.  
  372.     On Error GoTo 0
  373.  
  374.     '---------------------------------------------------------
  375.     '-- Reset properties
  376.     '---------------------------------------------------------
  377.     lblLink.LinkTimeout = OldLinkTimeout%
  378.     lblLink.LinkMode = 0
  379.         
  380.  
  381.     '---------------------------------------------------------
  382.     '-- Load the array with the names of the groups
  383.     '---------------------------------------------------------
  384.     Delimiter$ = Chr$(13) & Chr$(10)
  385.     GroupsParsedOK% = ParseString(GroupList$, arrGroups$(), Delimiter$)
  386.     If GroupsParsedOK% = True Then
  387.         ddepmGetGroups% = True
  388.     ElseIf GroupsParsedOK% = ERR_ITEMS_TRUNCATED Then
  389.         ddepmGetGroups% = ERR_ITEMS_TRUNCATED
  390.     End If
  391.  
  392.  
  393. ddepmGetGroupsExit:
  394.     Screen.MousePointer = DEFAULT
  395.     On Error GoTo 0
  396.     Exit Function
  397.  
  398.  
  399. ddepmGetGroupsError:
  400.     ddepmGetGroups% = False
  401.     Call ddepmErrorHandler(Err)
  402.     Resume ddepmGetGroupsExit
  403.  
  404.  
  405. End Function
  406.  
  407. Function ddepmGroupInfo% (txtLink As TextBox, GroupName$, tarrGroupItems() As T_ProgManGroupItem)
  408. '----------------------------------------------------------
  409. '-- This procedure will retrieve all the items in the
  410. '   specified group into an array of type variables. The
  411. '   array needs to be a dynamic array and this procedure
  412. '   will redimension it as necessary.
  413. '
  414. '-- Returns: True(-1) if no errors occur
  415. '            False(0) if a DDE error occurs which would
  416. '             indicate that no Item information was
  417. '             retrieved or if no group is specified.
  418. '            ERR_ITEMS_TRUNCATED(-2) if an error occurs
  419. '             while parsing the group information.
  420. '
  421. '-- NOTE: If the return code is -2 some elements may have
  422. '         been loaded successfully into the array.
  423. '
  424. '!! NOTE: Right now there is no distinction between
  425. '         truncation of Properties and Items. If Items are
  426. '         truncated it will still tell you things are OK
  427. '         as long as the Properties aren't truncated. This
  428. '         should be addressed.
  429. '
  430. '!! NOTE: This procedure is the only one that takes a
  431. '         Textbox as a parameter instead of a label. The
  432. '         reason for this is that the label will only
  433. '         return the first 1024 characters in it's caption
  434. '         which will truncate the large amount of data that
  435. '         we get with this call. Hmmm. I guess GetGroups
  436. '         could be overloaded as well. Make a note of that.
  437. '----------------------------------------------------------
  438.     Dim ItemIndex%
  439.     Dim OldLinkTimeout%
  440.     Dim ItemDelimiter$
  441.     Dim PropertyDelimiter$
  442.     Dim GroupItemInfo$
  443.     Dim ItemsParsedOK%
  444.     Dim ItemPropertiesParsedOK%
  445.  
  446.  
  447.     OldLinkTimeout% = txtLink.LinkTimeout
  448.  
  449.     '---------------------------------------------------------
  450.     '-- Default to retreiving list of available Groups
  451.     '   if GroupName is Null("")
  452.     '---------------------------------------------------------
  453.     If Len(GroupName$) = 0 Then
  454.         '-- Set return code to indicate error
  455.         ddepmGroupInfo% = False
  456.         Exit Function
  457.     End If
  458.  
  459.     '---------------------------------------------------------
  460.     '-- Set LinkTopic to PROGRAM MANAGER
  461.     '---------------------------------------------------------
  462.     txtLink.LinkTopic = "ProgMan|Progman"
  463.     txtLink.LinkMode = LINK_MANUAL
  464.     txtLink.LinkTimeout = 100
  465.     
  466.     On Error GoTo ddepmGroupInfoError
  467.         '---------------------------------------------------------
  468.         '-- Ask for the program manager group information
  469.         '   (returned in txtLink.Caption)
  470.         '---------------------------------------------------------
  471.         txtLink.LinkItem = GroupName$
  472.         txtLink.LinkRequest
  473.         
  474.     On Error GoTo 0
  475.  
  476.     '---------------------------------------------------------
  477.     '-- Reset properties
  478.     '---------------------------------------------------------
  479.     txtLink.LinkTimeout = OldLinkTimeout%
  480.     txtLink.LinkMode = 0
  481.         
  482.  
  483.     '---------------------------------------------------------
  484.     '-- Parse the data we got from ProgMan
  485.     '---------------------------------------------------------
  486.     ReDim arrItems$(0)
  487.     ReDim arrItemProperties$(0)
  488.     ItemDelimiter$ = Chr$(13) + Chr$(10)
  489.     PropertyDelimiter$ = ","
  490.     GroupItemInfo$ = txtLink.Text
  491.     
  492.     '-- Parse the big chunk we got back into lines which
  493.     '   each contain the data for a single item
  494.     ItemsParsedOK% = ParseString(GroupItemInfo$, arrItems$(), ItemDelimiter$)
  495.     If ItemsParsedOK% Then
  496.         
  497.         ReDim tarrGroupItems(UBound(arrItems$))
  498.         
  499.         For ItemIndex% = 0 To UBound(arrItems$)
  500.             
  501.             '-- Parse the line containing the item info into fields
  502.             '   so we can set them into our type variables.
  503.             ItemPropertiesParsedOK% = ParseString(arrItems$(ItemIndex%), arrItemProperties$(), PropertyDelimiter$)
  504.             If ItemPropertiesParsedOK% Then
  505.                 On Error Resume Next
  506.                     '-- The first line holds the GroupName and GroupPath. We don't
  507.                     '   need to strip quotes from the GroupPath but we do for the
  508.                     '   rest of the items.
  509.                     arrItemProperties$(0) = StripQuotes(arrItemProperties$(0))
  510.                     If ItemIndex% > 0 Then
  511.                         arrItemProperties$(1) = StripQuotes(arrItemProperties$(1))
  512.                     End If
  513.  
  514.                     '-- Fill the Type Variable with the properties we found
  515.                     tarrGroupItems(ItemIndex%).Name = arrItemProperties$(0)
  516.                     tarrGroupItems(ItemIndex%).CmdLine = arrItemProperties$(1)
  517.                     tarrGroupItems(ItemIndex%).DefaultDir = arrItemProperties$(2)
  518.                     tarrGroupItems(ItemIndex%).IconPath = arrItemProperties$(3)
  519.                     tarrGroupItems(ItemIndex%).xPos = Val(arrItemProperties$(4))
  520.                     tarrGroupItems(ItemIndex%).yPos = Val(arrItemProperties$(5))
  521.                     tarrGroupItems(ItemIndex%).IconIndex = Val(arrItemProperties$(6))
  522.                     tarrGroupItems(ItemIndex%).HotKey = Val(arrItemProperties$(7))
  523.                     tarrGroupItems(ItemIndex%).RunMinimized = Val(arrItemProperties$(8))
  524.                 On Error GoTo ddepmGroupInfoError
  525.             Else
  526.                 '-- Set the return code to indicate an error
  527.                 If ItemPropertiesParsedOK% = False Then
  528.                     ddepmGroupInfo% = False
  529.                 Else
  530.                     ItemPropertiesParsedOK% = ERR_ITEMS_TRUNCATED
  531.                 End If
  532.             End If
  533.         Next ItemIndex%
  534.     Else
  535.         '-- Set the return code to indicate an error
  536.         If ItemsParsedOK% = False Then
  537.             ddepmGroupInfo% = False
  538.         Else
  539.             ddepmGroupInfo% = ERR_ITEMS_TRUNCATED
  540.         End If
  541.  
  542.     End If
  543.  
  544.  
  545. ddepmGroupInfoExit:
  546.     Screen.MousePointer = DEFAULT
  547.     On Error GoTo 0
  548.     Exit Function
  549.     
  550.  
  551. ddepmGroupInfoError:
  552.     ddepmGroupInfo% = False
  553.     Call ddepmErrorHandler(Err)
  554.     Resume ddepmGroupInfoExit
  555.  
  556.  
  557. End Function
  558.  
  559. Sub ddepmReloadGroup (lblLink As Label, GroupName$)
  560. '-----------------------------------------------------------
  561. '-- Arguments: lblLink     The Label used for DDE with
  562. '                          Progman.
  563. '              GroupName$  Name of the Group to Reload.
  564. '-----------------------------------------------------------
  565.     Dim ddeCmd$
  566.     
  567.     ddeCmd$ = "[Reload (" & GroupName$ & ")]"
  568.     Call ddepmExecute(lblLink, ddeCmd$)
  569.  
  570.  
  571. End Sub
  572.  
  573. Sub ddepmReplaceItem (lblLink As Label, OldItem$, NewItemCmdLine$, NewItemName$)
  574. '-----------------------------------------------------------
  575. '-- Arguments: lblLink     The Label used for DDE with
  576. '                          Progman.
  577. '              OldItem$
  578. '              NewItemCmdLine$
  579. '              NewItemName$
  580. '-----------------------------------------------------------
  581.     Dim DDEReplaceItemCmd$
  582.     Dim DDEAddItemCmd$
  583.  
  584.     DDEReplaceItemCmd$ = "[ReplaceItem(" & OldItem$ & ")]"
  585.     Call ddepmExecute(lblLink, DDEReplaceItemCmd$)
  586.     
  587.     DDEAddItemCmd$ = "[AddItem(" & NewItemCmdLine$ & "," + NewItemName$ & ")]"
  588.     Call ddepmExecute(lblLink, DDEAddItemCmd$)
  589.  
  590.  
  591. End Sub
  592.  
  593. Sub ddepmSelectGroup (lblLink As Label, GroupName$)
  594. '----------------------------------------------------------
  595. '-- Arguments: lblLink     The Label used for DDE with
  596. '                          Progman.
  597. '              GroupName$  A string that contains the group
  598. '                          name to Show and Select.
  599. '
  600. '-- NOTE: This routine selects the group automatically
  601. '         rather than taking nCmd as a parameter. It also
  602. '         doesn't work if the Group is *not* minimized.
  603. '----------------------------------------------------------
  604.     Dim ddeCmd$
  605.  
  606.     ddeCmd$ = "[ShowGroup(" & GroupName$ & ",1)]"
  607.     Call ddepmExecute(lblLink, ddeCmd$)
  608.  
  609.  
  610. End Sub
  611.  
  612. Sub ddepmShowGroup (lblLink As Label, GroupName$, ShowCmd%)
  613. '--------------------------------------------------------------
  614. '-- Arguments: lblLink    The Label used for DDE with
  615. '                         Progman.
  616. '              GroupName$ A string that contains the group
  617. '                         name.
  618. '              ShowCmd%   The command for how the window
  619. '                         is to be displayed.
  620. '--------------------------------------------------------------
  621.     Dim ddeCmd$
  622.  
  623.     '-- Make sure ShowCmd% is valid
  624.     If (ShowCmd% < 1) Or (ShowCmd% > 8) Then
  625.         ShowCmd% = 1
  626.     End If
  627.     
  628.     ddeCmd$ = "[ShowGroup(" & GroupName$ + "," & ShowCmd% & ")]"
  629.     Call ddepmExecute(lblLink, ddeCmd$)
  630.  
  631.  
  632. End Sub
  633.  
  634. Private Function ParseString% (StringIn$, arrOut$(), Delimiter$)
  635. '----------------------------------------------------------
  636. '-- Returns: True as long as we don't bomb out due to
  637. '              a delimiter or String not being passed.
  638. '            ERR_ITEMS_TRUNCATED(-2) if we try to load more
  639. '              elements than exist in the array. If this is
  640. '              the case then some elements will have been
  641. '              loaded properly but some may have been
  642. '              truncated.
  643. '
  644. '-- StringIn$ = The string to parse
  645. '   arrOut$() = The array to fill (should be dynamic as
  646. '               it will be ReDim'ed in this procedure)
  647. '   Delimiter$= The character(s) separating the elements
  648. '               in Stringin$
  649. '----------------------------------------------------------
  650.     Dim LastItemPos%, NextItemPos%
  651.     Dim StartPos%
  652.     Dim ItemLen%
  653.     Dim DelimiterLength%
  654.     Dim NumItems%
  655.     Dim ItemNum%
  656.     Dim bGetLastItem%
  657.     
  658.     
  659.     If Len(StringIn$) = 0 Then
  660.         ParseString% = False
  661.         Exit Function
  662.     End If
  663.  
  664.     DelimiterLength% = Len(Delimiter$)
  665.     If DelimiterLength% = 0 Then
  666.         ParseString% = False
  667.         Exit Function
  668.     End If
  669.  
  670.     On Error Resume Next
  671.         '-----------------------------------------------------
  672.         '-- First time through we're just counting
  673.         '-----------------------------------------------------
  674.         NextItemPos% = InStr(StringIn$, Delimiter$)
  675.         While NextItemPos%
  676.             NumItems% = NumItems% + 1
  677.             StartPos% = NextItemPos% + DelimiterLength%
  678.             NextItemPos% = InStr(StartPos%, StringIn$, Delimiter$)
  679.         Wend
  680.         
  681.         '-----------------------------------------------------
  682.         '-- We now know how many items are in the string so
  683.         '   we can initialize our array. The exception to this
  684.         '   would be if the Delimiter is the last thing in the
  685.         '   string in which case we need to ReDim to one less
  686.         '   item than we counted.
  687.         '-----------------------------------------------------
  688.         If StartPos% <> Len(StringIn$) + 1 Then
  689.             ReDim arrOut$(NumItems%)
  690.             '-- Set a flag so we know to get the last element
  691.             bGetLastItem% = True
  692.         Else
  693.             ReDim arrOut$(NumItems% - 1)
  694.         End If
  695.  
  696.         '-- This needs to be initialized
  697.         LastItemPos% = 1
  698.         
  699.         '-----------------------------------------------------
  700.         '-- Now it's for real. Get the items from the string.
  701.         '-----------------------------------------------------
  702.         NextItemPos% = InStr(StringIn$, Delimiter$)
  703.         While NextItemPos%
  704.             StartPos% = LastItemPos%
  705.             ItemLen% = (NextItemPos% - LastItemPos%)
  706.             
  707.             arrOut$(ItemNum%) = Mid$(StringIn$, StartPos%, ItemLen%)
  708.             ItemNum% = ItemNum% + 1
  709.             If ItemNum% > UBound(arrOut$) Then
  710.                 ParseString = ERR_ITEMS_TRUNCATED
  711.                 Exit Function
  712.             End If
  713.             
  714.             LastItemPos% = NextItemPos% + DelimiterLength%
  715.             NextItemPos% = InStr(LastItemPos%, StringIn$, Delimiter$)
  716.         Wend
  717.  
  718.         '-- If the bGetLastItem% flag is on then
  719.         '   we have one more element to get.
  720.         If bGetLastItem% Then
  721.             arrOut$(ItemNum%) = Mid$(StringIn$, LastItemPos%)
  722.         End If
  723.     
  724.     On Error GoTo 0
  725.  
  726.     ParseString% = True
  727.  
  728. End Function
  729.  
  730. Function pmItemCmdLineFromTypeVar$ (tItem As T_ProgManGroupItem)
  731. '----------------------------------------------------------
  732. '
  733. '-- Used by: ddepmAddItemExtT
  734. '----------------------------------------------------------
  735.     Dim CmdLine$
  736.     
  737.     CmdLine$ = ""
  738.     CmdLine$ = tItem.CmdLine$ & "," & tItem.Name$ & "," & tItem.IconPath$
  739.     CmdLine$ = CmdLine$ & tItem.IconIndex% & "," & tItem.xPos% & "," & tItem.yPos%
  740.     CmdLine$ = CmdLine$ & tItem.DefaultDir$ & "," & tItem.HotKey% & "," & tItem.RunMinimized%
  741.  
  742.     pmItemCmdLineFromTypeVar$ = CmdLine$
  743.  
  744. End Function
  745.  
  746. Private Function StripQuotes$ (theString$)
  747. '-- This was just added as a quickie when I got the
  748. '   item info stuff working and decided to strip off
  749. '   the quotes.
  750.  
  751.     StripQuotes$ = Mid$(theString$, 2, Len(theString$) - 2)
  752.  
  753. End Function
  754.  
  755.